home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / misc / amag / 9301b.lha / Schach / Sourcecode / Grafik.c < prev    next >
C/C++ Source or Header  |  1992-12-15  |  25KB  |  765 lines

  1.  
  2.  /* Grafik.c : alles rechnerabhängige */
  3.  
  4. #include "Adt.h"
  5.  
  6. #include <exec/memory.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <libraries/dos.h>
  9. #include <libraries/dosextens.h>
  10. #include <libraries/filehandler.h>
  11. #include <clib/intuition_protos.h>
  12. #include <clib/graphics_protos.h>
  13. #include <clib/dos_protos.h>
  14.  
  15. #include <ctype.h>
  16. #include <stdio.h>
  17. #include <fcntl.h>
  18.  
  19. //#include <functions.h>
  20.  
  21. extern void SpielstaerkeAnzeige(void);
  22. extern void DruckeProtokoll();
  23.  
  24. extern int Spielstaerke;
  25.  
  26.  /* Library-Base-Pointer: */
  27. struct GfxBase *GfxBase = 0L;
  28. struct IntuitionBase *IntuitionBase = 0L;
  29.  
  30. struct Screen *scr = 0L;
  31. struct Window *win = 0L;
  32. struct RastPort *rp;
  33. UWORD bline;
  34.  
  35.  /* Protokoll- und Spielbrett-Datei-Handles: */
  36. struct FileHandle *pfh = 0L;
  37. struct FileHandle *sfh = 0L;
  38.  
  39.  /* Zeichensatz: */
  40. struct TextAttr font =
  41.   { (STRPTR)"topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  42.  
  43. struct NewScreen ns =
  44.   { 0, 0, 640, 256, 1, 0, 1, HIRES, CUSTOMSCREEN, &font, (UBYTE *)
  45.   "chss v1.1", NULL, NULL };
  46. struct NewWindow nw =
  47.   { 0, 11, 640, 245, 0, 1, CLOSEWINDOW | MOUSEBUTTONS | RAWKEY, WINDOWCLOSE |
  48.   SMART_REFRESH | ACTIVATE | RMBTRAP, NULL, NULL, (UBYTE *)"Spielbrett - <F1> - <F3> ändert Spielstärke, <F5> druckt Protokoll aus",
  49.   NULL, NULL, 0, 0, 0, 0, CUSTOMSCREEN };
  50.  
  51.  /* Lade-Fenster: */
  52. struct NewWindow nwl =
  53.   { 89, 90, 462, 87, 0, 1, GADGETUP, SMART_REFRESH | ACTIVATE, NULL,
  54.   NULL, (UBYTE *)"Spielnamen eingeben", NULL, NULL, 0, 0, 0, 0,
  55.   CUSTOMSCREEN };
  56. unsigned char strbuf[25];
  57. struct StringInfo str4 =
  58.   { strbuf, NULL, 0, 25, 0, 0, 0, 25, 0, 0, NULL, 0, NULL };
  59. struct Gadget gad4 =
  60.   { NULL, 131, 48, 200, 8, GADGHCOMP, RELVERIFY | STRINGCENTER, STRGADGET,
  61.   NULL, NULL, NULL, 0, (APTR)&str4, 4, NULL };
  62.  
  63.  /* Sicherheitsabfrage-Fenster: */
  64. struct NewWindow nws =
  65.   { 175, 73, 290, 109, 0, 1, GADGETUP, SMART_REFRESH | ACTIVATE | RMBTRAP,
  66.   NULL, NULL, (UBYTE *)"Sicherheitsabfrage", NULL, NULL, 0, 0, 0, 0,
  67.   CUSTOMSCREEN };
  68. struct Gadget gad1 =
  69.   { NULL, 20, 38, 70, 60, GADGHCOMP, RELVERIFY, BOOLGADGET, NULL, NULL,
  70.   NULL, 0, NULL, 1, NULL };
  71. struct Gadget gad2 =
  72.   { NULL, 110, 38, 70, 60, GADGHCOMP, RELVERIFY, BOOLGADGET, NULL, NULL,
  73.   NULL, 0, NULL, 2, NULL };
  74. struct Gadget gad3 =
  75.   { NULL, 200, 38, 70, 60, GADGHCOMP, RELVERIFY, BOOLGADGET, NULL, NULL,
  76.   NULL, 0, NULL, 3, NULL };
  77.  
  78.  /* Schachfigurenbilder: */
  79. USHORT *bilder = 0L;
  80. USHORT rohbilder[ 720 ] = {
  81.    /* wbauer auf weiss: */
  82.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  83.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  84.   0xffff, 0x03ff, 0xff00, 0xfffe, 0xfdff, 0xff00, 0xfffd, 0xfcff, 0xff00,
  85.   0xfffe, 0xfdff, 0xff00, 0xffff, 0x7bff, 0xff00, 0xffff, 0x7bff, 0xff00,
  86.   0xfffe, 0xfdff, 0xff00, 0xfffd, 0xfe7f, 0xff00, 0xfffb, 0xffbf, 0xff00,
  87.   0xffe7, 0xff9f, 0xff00, 0xffcf, 0xffcf, 0xff00, 0xffc0, 0x000f, 0xff00,
  88.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  89.    /* wspringer auf weiss: */
  90.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00, 0xfffc, 0x007f, 0xff00,
  91.   0xfff1, 0xff3f, 0xff00, 0xff8f, 0x9f07, 0xff00, 0xff9f, 0xff7f, 0xff00,
  92.   0xffc0, 0x7f1f, 0xff00, 0xffff, 0xbf4f, 0xff00, 0xffff, 0x3f7f, 0xff00,
  93.   0xfffe, 0x7f1f, 0xff00, 0xfffc, 0xfee7, 0xff00, 0xfffd, 0xfeff, 0xff00,
  94.   0xfffb, 0xff7f, 0xff00, 0xfff3, 0xff3f, 0xff00, 0xfff7, 0xffbf, 0xff00,
  95.   0xffef, 0xff9f, 0xff00, 0xffcf, 0xffcf, 0xff00, 0xffc0, 0x000f, 0xff00,
  96.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  97.    /* wlaeufer auf weiss: */
  98.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00, 0xffff, 0xe3ff, 0xff00,
  99.   0xffff, 0x1bff, 0xff00, 0xffff, 0x773f, 0xff00, 0xffff, 0x743f, 0xff00,
  100.   0xffff, 0x717f, 0xff00, 0xffff, 0x7e7f, 0xff00, 0xffff, 0x7eff, 0xff00,
  101.   0xffff, 0x7eff, 0xff00, 0xfffe, 0x7cff, 0xff00, 0xfffd, 0xfcff, 0xff00,
  102.   0xfffd, 0xfeff, 0xff00, 0xfffb, 0xff7f, 0xff00, 0xfff3, 0xff3f, 0xff00,
  103.   0xfff7, 0xffbf, 0xff00, 0xffef, 0xff9f, 0xff00, 0xffe0, 0x001f, 0xff00,
  104.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  105.    /* wturm auf weiss: */
  106.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00, 0xfff9, 0x227f, 0xff00,
  107.   0xfff9, 0x227f, 0xff00, 0xfffa, 0xdd7f, 0xff00, 0xfffb, 0xff7f, 0xff00,
  108.   0xfffb, 0xff7f, 0xff00, 0xfffb, 0xff7f, 0xff00, 0xfffb, 0xff7f, 0xff00,
  109.   0xfffb, 0xff7f, 0xff00, 0xfffb, 0xff7f, 0xff00, 0xfffb, 0xff7f, 0xff00,
  110.   0xfffb, 0xff7f, 0xff00, 0xfffb, 0xff7f, 0xff00, 0xfff3, 0xff3f, 0xff00,
  111.   0xfff7, 0xffbf, 0xff00, 0xffef, 0xff9f, 0xff00, 0xffe0, 0x001f, 0xff00,
  112.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  113.    /* wdame auf weiss: */
  114.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00, 0xfff9, 0xf39f, 0xff00,
  115.   0xfffc, 0x621f, 0xff00, 0xfffc, 0x817f, 0xff00, 0xfffe, 0xfeff, 0xff00,
  116.   0xfffe, 0x3dff, 0xff00, 0xffff, 0xbdff, 0xff00, 0xffff, 0xb9ff, 0xff00,
  117.   0xffff, 0xbbff, 0xff00, 0xffff, 0xb9ff, 0xff00, 0xffff, 0x19ff, 0xff00,
  118.   0xfffe, 0x44ff, 0xff00, 0xfff8, 0xfe7f, 0xff00, 0xfff3, 0xff3f, 0xff00,
  119.   0xfff7, 0xffbf, 0xff00, 0xffef, 0xff9f, 0xff00, 0xffe0, 0x001f, 0xff00,
  120.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  121.    /* wkoenig auf weiss: */
  122.   0xffff, 0xffff, 0xff00, 0xffff, 0xcfff, 0xff00, 0xffff, 0x03ff, 0xff00,
  123.   0xffff, 0xcfff, 0xff00, 0xffff, 0xcfff, 0xff00, 0xfffe, 0x01ff, 0xff00,
  124.   0xffff, 0x7bff, 0xff00, 0xfffe, 0x79ff, 0xff00, 0xfffe, 0xfdff, 0xff00,
  125.   0xfffe, 0xfcff, 0xff00, 0xfffc, 0x30ff, 0xff00, 0xfffd, 0x8eff, 0xff00,
  126.   0xfff9, 0xfeff, 0xff00, 0xfff9, 0xfe7f, 0xff00, 0xfff2, 0x013f, 0xff00,
  127.   0xfff7, 0xffbf, 0xff00, 0xffef, 0xff9f, 0xff00, 0xffe0, 0x001f, 0xff00,
  128.   0xffff, 0xffff, 0xff00, 0xffff, 0xffff, 0xff00,
  129.    /* wbauer auf schwarz: */
  130.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  131.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  132.   0x0000, 0xfc00, 0x0000, 0x0001, 0xfe00, 0x0000, 0x0003, 0xff00, 0x0000,
  133.   0x0001, 0xfe00, 0x0000, 0x0000, 0xfc00, 0x0000, 0x0000, 0xfc00, 0x0000,
  134.   0x0001, 0xfe00, 0x0000, 0x0003, 0xff80, 0x0000, 0x0007, 0xffc0, 0x0000,
  135.   0x001f, 0xffe0, 0x0000, 0x003f, 0xfff0, 0x0000, 0x003f, 0xfff0, 0x0000,
  136.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  137.    /* wspringer auf schwarz: */
  138.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0xff80, 0x0000,
  139.   0x000f, 0xffc0, 0x0000, 0x007f, 0x9ff8, 0x0000, 0x007f, 0xff80, 0x0000,
  140.   0x003f, 0xffe0, 0x0000, 0x0000, 0x7fb0, 0x0000, 0x0000, 0xff80, 0x0000,
  141.   0x0001, 0xffe0, 0x0000, 0x0003, 0xff18, 0x0000, 0x0003, 0xff00, 0x0000,
  142.   0x0007, 0xff80, 0x0000, 0x000f, 0xffc0, 0x0000, 0x000f, 0xffc0, 0x0000,
  143.   0x001f, 0xffe0, 0x0000, 0x003f, 0xfff0, 0x0000, 0x003f, 0xfff0, 0x0000,
  144.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  145.    /* wlaeufer auf schwarz: */
  146.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1c00, 0x0000,
  147.   0x0000, 0xfc00, 0x0000, 0x0000, 0xf8c0, 0x0000, 0x0000, 0xfbc0, 0x0000,
  148.   0x0000, 0xff80, 0x0000, 0x0000, 0xff80, 0x0000, 0x0000, 0xff00, 0x0000,
  149.   0x0000, 0xff00, 0x0000, 0x0001, 0xff00, 0x0000, 0x0003, 0xff00, 0x0000,
  150.   0x0003, 0xff00, 0x0000, 0x0007, 0xff80, 0x0000, 0x000f, 0xffc0, 0x0000,
  151.   0x000f, 0xffc0, 0x0000, 0x001f, 0xffe0, 0x0000, 0x001f, 0xffe0, 0x0000,
  152.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  153.    /* wturm auf schwarz: */
  154.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0006, 0xdd80, 0x0000,
  155.   0x0006, 0xdd80, 0x0000, 0x0007, 0xff80, 0x0000, 0x0007, 0xff80, 0x0000,
  156.   0x0007, 0xff80, 0x0000, 0x0007, 0xff80, 0x0000, 0x0007, 0xff80, 0x0000,
  157.   0x0007, 0xff80, 0x0000, 0x0007, 0xff80, 0x0000, 0x0007, 0xff80, 0x0000,
  158.   0x0007, 0xff80, 0x0000, 0x0007, 0xff80, 0x0000, 0x000f, 0xffc0, 0x0000,
  159.   0x000f, 0xffc0, 0x0000, 0x001f, 0xffe0, 0x0000, 0x001f, 0xffe0, 0x0000,
  160.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  161.    /* wdame auf schwarz: */
  162.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0006, 0x0c60, 0x0000,
  163.   0x0003, 0x9de0, 0x0000, 0x0003, 0xff80, 0x0000, 0x0001, 0xff00, 0x0000,
  164.   0x0001, 0xfe00, 0x0000, 0x0000, 0x7e00, 0x0000, 0x0000, 0x7e00, 0x0000,
  165.   0x0000, 0x7c00, 0x0000, 0x0000, 0x7e00, 0x0000, 0x0000, 0xde00, 0x0000,
  166.   0x0001, 0xc700, 0x0000, 0x0007, 0xff80, 0x0000, 0x000f, 0xffc0, 0x0000,
  167.   0x000f, 0xffc0, 0x0000, 0x001f, 0xffe0, 0x0000, 0x001f, 0xffe0, 0x0000,
  168.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  169.    /* wkoenig auf schwarz: */
  170.   0x0000, 0x0000, 0x0000, 0x0000, 0x3000, 0x0000, 0x0000, 0xfc00, 0x0000,
  171.   0x0000, 0x3000, 0x0000, 0x0000, 0x3000, 0x0000, 0x0001, 0xfe00, 0x0000,
  172.   0x0000, 0xfc00, 0x0000, 0x0001, 0xfe00, 0x0000, 0x0001, 0xfe00, 0x0000,
  173.   0x0001, 0xff00, 0x0000, 0x0003, 0x3300, 0x0000, 0x0003, 0x8f00, 0x0000,
  174.   0x0007, 0xff00, 0x0000, 0x0007, 0xff80, 0x0000, 0x000e, 0x01c0, 0x0000,
  175.   0x000f, 0xffc0, 0x0000, 0x001f, 0xffe0, 0x0000, 0x001f, 0xffe0, 0x0000,
  176.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
  177. struct Image bild = { 0, 0, 40, 20, 1, 0, 1, 0, 0 };
  178.  
  179.  /* für NotierZug und NotierAdd: */
  180. int zuege = -1, nfarbe = schwarz;
  181.  
  182.  
  183. OeffneDisplay()
  184. {
  185.     int i, j;
  186.  
  187.      /* Speicher für Bilder der Schachfiguren: */
  188.     if(( bilder = (USHORT *)AllocMem( 2880L, MEMF_CHIP )) == 0L ) {
  189.         SchliesseDisplay(); exit( 1 );
  190.     }
  191.     for( i=0; i<360; i++ ) {
  192.         *(bilder+i) = rohbilder[ i ];
  193.         *(bilder+i+360) = rohbilder[ i+360 ];
  194.         *(bilder+i+720) = ~rohbilder[ i+360 ];
  195.         *(bilder+i+1080) = ~rohbilder[ i ];
  196.     }
  197.  
  198.      /* Libraries öffnen: */
  199.     if(( GfxBase = (struct GfxBase *)
  200.       OpenLibrary( "graphics.library", 0L )) == 0L ) {
  201.         SchliesseDisplay(); exit( 1 );
  202.     }
  203.     if(( IntuitionBase = (struct IntuitionBase *)
  204.       OpenLibrary( "intuition.library", 0L )) == 0L ) {
  205.         SchliesseDisplay(); exit( 1 );
  206.     }
  207.  
  208.      /* Screen und Window öffnen: */
  209.     if(( scr = OpenScreen( &ns )) == 0L ) {
  210.         SchliesseDisplay(); exit( 1 );
  211.     }
  212.     nw.Screen = scr;
  213.     if(( win = OpenWindow( &nw )) == 0L ) {
  214.         SchliesseDisplay(); exit( 1 );
  215.     }
  216.     rp = win->RPort;
  217.     bline = rp->TxBaseline;
  218.  
  219.      /* Spielbrett umrahmen: */
  220.     HLinie( 44, 20, 383 );      VLinie( 382, 20, 189 );
  221.     HLinie( 383, 189, 44 );     VLinie( 44, 189, 20 );
  222.     HLinie( 48, 22, 379 );      VLinie( 378, 22, 187 );
  223.     HLinie( 379, 187, 48 );     VLinie( 48, 187, 22 );
  224.     HLinie( 52, 24, 375 );      VLinie( 374, 24, 185 );
  225.     HLinie( 375, 185, 52 );     VLinie( 52, 185, 24 );
  226.  
  227.     HLinie( 24, 212, 383 );     HLinie( 24, 214, 383 );
  228.     HLinie( 24, 231, 383 );     HLinie( 24, 233, 383 );
  229.     for( i=0; i<4; i++ )
  230.         HLinie( 64 + i*80, 213, 103 + i*80 );
  231.     for( i=0; i<5; i++ )
  232.         HLinie( 24 + i*80, 232, 63 + i*80 );
  233.     Move( rp, 76L, (long)219+bline );
  234.     Text( rp, "Dezember '92 von Robert Junghans", 32L );
  235.  
  236.     VLinie( 404, 22, 181 );     VLinie( 408, 22, 181 );
  237.     VLinie( 610, 22, 181 );     VLinie( 614, 22, 181 );
  238.     for( i=0; i<4; i++ ) {
  239.         VLinie( 406, 22 + i*40, 41 + i*40 );
  240.         VLinie( 612, 42 + i*40, 61 + i*40 );
  241.     }
  242.     Move( rp, 474L, (long)20+bline );
  243.     Text( rp, "Zugliste:", 9L );
  244.  
  245.     VLinie( 404, 194, 233 );    VLinie( 408, 194, 233 );
  246.     VLinie( 610, 194, 233 );    VLinie( 614, 194, 233 );
  247.     VLinie( 406, 194, 213 );    VLinie( 612, 214, 233 );
  248.     Move( rp, 478L, (long)196+bline );
  249.     Text( rp, "Zuginfo:", 8L );
  250. }
  251.  
  252. ZeichneBrett( s, fa )
  253.     Figur s[ 9 ][ 9 ];
  254.     Farbe fa;
  255. {
  256.     static char buchst[ 2 ][ 9 ] = { "hgfedcba", "abcdefgh" };
  257.     static char zahl[ 2 ][ 9 ]   = { "12345678", "87654321" };
  258.     int ufarw, i, j;
  259.     Feld fe;
  260.  
  261.      /* Spielfeldbezeichnungen am Rand: */
  262.     ufarw = fa == weiss;
  263.     for( i=0; i<8; i++ ) {
  264.         Move( rp, 28L, (long)31 + i*20 + bline );
  265.         Text( rp, &(zahl[ ufarw ][ i ]), 1L );
  266.         Move( rp, (long)70 + i*40, (long)194+bline );
  267.         Text( rp, &(buchst[ ufarw ][ i ]), 1L );
  268.     }
  269.  
  270.      /* indiv. Umrahmung des Spielbrettes: */
  271.     SetAPen( rp, (long)ufarw );
  272.     HLinie( 94, 21, 133 );      HLinie( 174, 21, 213 );
  273.     HLinie( 254, 21, 293 );     HLinie( 334, 21, 381 );
  274.     VLinie( 380, 21, 44 );      VLinie( 380, 65, 84 );
  275.     VLinie( 380, 105, 124 );    VLinie( 380, 145, 164 );
  276.     HLinie( 333, 188, 294 );    HLinie( 253, 188, 214 );
  277.     HLinie( 173, 188, 134 );    HLinie( 93, 188, 46 );
  278.     VLinie( 46, 188, 165 );     VLinie( 46, 144, 125 );
  279.     VLinie( 46, 104, 85 );      VLinie( 46, 64, 45 );
  280.     SetAPen( rp, (long)!ufarw );
  281.     HLinie( 46, 21, 93 );       HLinie( 134, 21, 173 );
  282.     HLinie( 214, 21, 253 );     HLinie( 294, 21, 333 );
  283.     VLinie( 380, 45, 64 );      VLinie( 380, 85, 104 );
  284.     VLinie( 380, 125, 144 );    VLinie( 380, 165, 188 );
  285.     HLinie( 381, 188, 334 );    HLinie( 293, 188, 254 );
  286.     HLinie( 213, 188, 174 );    HLinie( 133, 188, 94 );
  287.     VLinie( 46, 164, 145 );     VLinie( 46, 124, 105 );
  288.     VLinie( 46, 84, 65 );       VLinie( 46, 44, 21 );
  289.     SetAPen( rp, 1L );
  290.  
  291.      /* Spielbrett mit Figuren zeichnen: */
  292.     for( i=1; i<=8; i++ )
  293.         for( j=1; j<=8; j++ ) {
  294.             fe = i << 4 | j;
  295.             ZeichneFigur( s[ i ][ j ], fe, fa );
  296.         }
  297. }
  298.  
  299. struct Ereignis * WarteEreignis( s, fa, sp )
  300.     Figur s[ 9 ][ 9 ];
  301.     Farbe fa;
  302.     Special sp;
  303. {
  304.     static struct Ereignis e;
  305.     struct IntuiMessage *msg;
  306.     Feld feld1, feld;
  307.     ULONG class,code;
  308.     SHORT x, y;
  309.     int sx, sy, fx, fy, ok;
  310.     Figur merk;
  311.  
  312.     feld1 = 0;
  313.     while( 1 ) {
  314.          /* eine Message holen: */
  315.         while(( msg = (struct IntuiMessage *)GetMsg( win->UserPort )) == 0L )
  316.             Wait( 1L << win->UserPort->mp_SigBit );
  317.         class = msg->Class;
  318.         code = msg->Code;
  319.         x = msg->MouseX;
  320.         y = msg->MouseY;
  321.         ReplyMsg( msg );
  322.  
  323.         if( class & CLOSEWINDOW ) {
  324.             e.ereignistyp = ende;
  325.             return( &e );
  326.         } else if( class & RAWKEY ) {
  327.           /*
  328.            * F1 bis F3 ändert die Spielstärke
  329.            */
  330.           if( code >= 0x50 && code <= 0x52 ) {
  331.             /*
  332.              * OK, liegt im Bereich
  333.              */
  334.             Spielstaerke=2+(code-0x50);
  335.             if( Spielstaerke < 2 )
  336.               Spielstaerke=2;
  337.             if( Spielstaerke > 4 )
  338.               Spielstaerke=4;
  339.             SpielstaerkeAnzeige();
  340.           } else if( code == 0x54 ) {
  341.             /*
  342.              * Ausdrucken
  343.              */
  344.             DruckeProtokoll();
  345.           }
  346.         } else { /* kann nur MOUSEBUTTONS sein */
  347.              /* Feldkoordinaten ermitteln: */
  348.             if( fa == weiss) {
  349.                 fx = (x-14)/40; fy = (204-y)/20;
  350.             } else {
  351.                 fx = (413-x)/40; fy = (y-5)/20;
  352.             }
  353.  
  354.              /* prüfen, ob halbwegs annehmbar geklickt: */
  355.             if( fx >= 1 && fx <= 8 && fy >= 1 && fy <= 8 ) {
  356.                 feld = fx << 4 | fy;
  357.                  /* ist es das zweite Klicken und 'ordentlicher' Zug? */
  358.                 if( feld1 && ZugOK( s, feld1, feld, sp ) ) {
  359.  
  360.                      /* prüfen, ob Spieler nicht ins Schach zieht: */
  361.                     sx = feld1 >> 4;    sy = feld1 & yposmask;
  362.                     merk = s[ fx ][ fy ];
  363.                     s[ fx ][ fy ] = s[ sx ][ sy ];
  364.                     s[ sx ][ sy ] = leer;
  365.                     ok = !IstSchach( s, fa, 0, sp );
  366.                     s[ sx ][ sy ] = s[ fx ][ fy ];
  367.                     s[ fx ][ fy ] = merk;
  368.  
  369.                     if( ok ) { /* prima Zug, wird genommen */
  370.                         e.ereignistyp = zugs;
  371.                         e.zug.figur = s[ sx ][ sy ];
  372.                         e.zug.start = feld1;
  373.                         e.zug.ziel = feld;
  374.                         return( &e );
  375.                     }
  376.                 } else /* vielleicht das erste Klicken */
  377.                     if( (s[ fx ][ fy ] & farbmask) == fa)
  378.                         feld1 = feld;
  379.             }
  380.         }
  381.     }
  382. }
  383.  
  384. WillLaden( s, sp )
  385.     Figur s[ 9 ][ 9 ];
  386.     Special *sp;
  387. {
  388.     struct Window *winl;
  389.     struct RastPort *rpl;
  390.     struct IntuiMessage *msg;
  391.     unsigned char sbuf[36], pbuf[35];
  392.  
  393.     nwl.Screen = scr;
  394.     if(( winl = OpenWindow( &nwl )) == 0L )
  395.     return 0;
  396.     rpl = winl->RPort;
  397.  
  398.     Move( rpl, 23L, (long)21+bline );
  399.     Text( rpl, "Geben Sie bitte einen Namen für das zu ladende Spiel", 52L );
  400.     Move( rpl, 15L, (long)29+bline );
  401.     Text( rpl, "bzw. unter dem das Spiel gespeichert werden soll, ein:", 54L );
  402.     Move( rpl, 130L, 47L );    Draw( rpl, 331L, 47L );
  403.     Draw( rpl, 331L, 56L );    Draw( rpl, 130L, 56L );
  404.     Draw( rpl, 130L, 47L );
  405.     Move( rpl, 45L, (long)67+bline );
  406.     Text( rpl, "<Return> = neues Spiel, kein Speichern erwünscht.", 49L );
  407.     AddGadget( winl, &gad4, -1L );
  408.     Delay( 10L );
  409.     ActivateGadget( &gad4, winl, NULL );
  410.  
  411.      /* auf die Return-Taste warten: */
  412.     while(( msg = (struct IntuiMessage *)GetMsg( winl->UserPort )) == 0L )
  413.     Wait( 1L << winl->UserPort->mp_SigBit );
  414.     ReplyMsg( msg );
  415.     CloseWindow( winl );
  416.  
  417.      /* MessagePort-queue des 'Haupt'-Windows leeren: */
  418.     while( msg = (struct IntuiMessage *)GetMsg( win->UserPort ) )
  419.     ReplyMsg( msg );
  420.  
  421.      /* kein Name? */
  422.     if( !strcmp( strbuf, "" ) )
  423.     return 0;
  424.  
  425.     strcpy( sbuf, strbuf );    strcat( sbuf, ".spielbrett" );
  426.     strcpy( pbuf, strbuf );    strcat( pbuf, ".protokoll" );
  427.     if( pfh = Open( pbuf, MODE_OLDFILE ) ) {
  428.     if( sfh = Open( sbuf, MODE_OLDFILE ) ) {
  429.         LadeBrett( s, sp );
  430.         Seek( pfh, 0L, OFFSET_END );
  431.         return 1;
  432.     } else {
  433.         Close( pfh );
  434.         pfh = 0L;
  435.         return 0;
  436.     }
  437.     } else {
  438.     if( pfh = Open( pbuf, MODE_NEWFILE ) ) {
  439.         if( sfh = Open( sbuf, MODE_NEWFILE ) ) {
  440.         return 0;
  441.         } else {
  442.         Close( pfh );
  443.         pfh = 0L;
  444.         return 0;
  445.         }
  446.     }
  447.     }
  448. }
  449.  
  450. WillBeenden( s, sp )
  451.     Figur s[ 9 ][ 9 ];
  452.     Special sp;
  453. {
  454.     struct Window *wins;
  455.     struct RastPort *rps;
  456.     struct IntuiMessage *msg;
  457.     USHORT id;
  458.  
  459.      /* Window öffnen: */
  460.     nws.Screen = scr;
  461.     if(( wins = OpenWindow( &nws )) == 0L )
  462.         return 1;
  463.     rps = wins->RPort;
  464.  
  465.     Move( rps, 29L, (long)20+bline );
  466.     Text( rps, "Wollen Sie das Spiel beenden?", 29L );
  467.     Move( rps, 20L, 38L );      Draw( rps, 89L, 38L );
  468.     Draw( rps, 89L, 97L );      Draw( rps, 20L, 97L );
  469.     Draw( rps, 20L, 38L );      Move( rps, 200L, 38L );
  470.     Draw( rps, 269L, 38L );     Draw( rps, 269L, 97L );
  471.     Draw( rps, 200L, 97L );     Draw( rps, 200L, 38L );
  472.     Move( rps, 47L, (long)64+bline );   Text( rps, "ja", 2L );
  473.     Move( rps, 227L, (long)64+bline );  Text( rps, "nö", 2L );
  474.     AddGadget( wins, &gad1, -1L );
  475.     AddGadget( wins, &gad3, -1L );
  476.  
  477.     if( pfh ) {
  478.     Move( rps, 110L, 38L );        Draw( rps, 179L, 38L );
  479.     Draw( rps, 179L, 97L );        Draw( rps, 110L, 97L );
  480.     Draw( rps, 110L, 38L );
  481.     Move( rps, 117L, (long)64+bline );  Text( rps, "sichern", 7L );
  482.         AddGadget( wins, &gad2, -1L );
  483.     }
  484.  
  485.      /* auf Entscheidung warten: */
  486.     while(( msg = (struct IntuiMessage *)GetMsg( wins->UserPort )) == 0L )
  487.         Wait( 1L << wins->UserPort->mp_SigBit );
  488.     id = ((struct Gadget *)msg->IAddress)->GadgetID;
  489.     ReplyMsg( msg );
  490.     CloseWindow( wins );
  491.  
  492.      /* MessagePort-queue des 'Haupt'-Windows leeren: */
  493.     while( msg = (struct IntuiMessage *)GetMsg( win->UserPort ) )
  494.         ReplyMsg( msg );
  495.  
  496.      /* evtl. Spielbrett sichern: */
  497.     if( id == 2 )
  498.         SicherBrett( s, sp );
  499.  
  500.     return( id == 1 );
  501. }
  502.  
  503. SicherBrett( s, sp )
  504.     Figur s[ 9 ][ 9 ];
  505.     Special sp;
  506. {
  507.     int i, j;
  508.  
  509.     Seek( sfh, 0L, OFFSET_BEGINNING );
  510.     for( i=1; i<=8; i++ )
  511.     for( j=1; j<=8; j++ )
  512.         Write( sfh, &s[ i ][ j ], (long)sizeof( Figur ) );
  513.     Write( sfh, &sp, (long)sizeof( Special ) );
  514.     Write( sfh, &zuege, (long)sizeof(int) );
  515. }
  516.  
  517. LadeBrett( s, sp )
  518.     Figur s[ 9 ][ 9 ];
  519.     Special *sp;
  520. {
  521.     int i, j;
  522.  
  523.     Seek( sfh, 0L, OFFSET_BEGINNING );
  524.     for( i=1; i<=8; i++ )
  525.     for( j=1; j<=8; j++ )
  526.         Read( sfh, &s[ i ][ j ], (long)sizeof( Figur ) );
  527.     Read( sfh, sp, (long)sizeof( Special ) );
  528.     Read( sfh, &zuege, (long)sizeof(int) );
  529. }
  530.  
  531. SchliesseDisplay()
  532. {
  533.      /* Window und Screen schliessen: */
  534.     if( win )
  535.         CloseWindow( win );
  536.     if( scr )
  537.         CloseScreen( scr );
  538.  
  539.      /* Libraries schliessen: */
  540.     if( IntuitionBase )
  541.         CloseLibrary( IntuitionBase );
  542.     if( GfxBase )
  543.         CloseLibrary( GfxBase );
  544.  
  545.      /* Dateien schliessen: */
  546.     if( pfh )
  547.     Close( pfh );
  548.     if( sfh )
  549.     Close( sfh );
  550.  
  551.      /* Speicher für Bilder freigeben: */
  552.     if( bilder )
  553.         FreeMem( bilder, 2880L );
  554. }
  555.  
  556. ZeichneFigur( fi, fe, fa )
  557.     Figur fi;
  558.     Feld fe;
  559.     Farbe fa;
  560. {
  561.     int hgrunds;
  562.     int px, py, x, y;
  563.  
  564.      /* Bildschirmposition und Spielbrettfarbe: */
  565.     px = fe >> 4;
  566.     py = fe & yposmask;
  567.     hgrunds = px + py & 1 ? 0 : 1;
  568.     if( fa == weiss ) {
  569.         x = 14 + px*40; y = 185 - py*20;
  570.     } else {
  571.         x = 374 - px*40; y = 5 + py*20;
  572.     }
  573.  
  574.     if( fi == leer ) {
  575.         SetAPen( rp, (long)!hgrunds );
  576.         RectFill( rp, (long)x, (long)y, (long)x+39, (long)y+19 );
  577.         SetAPen( rp, 1L );
  578.     } else {
  579.         bild.ImageData = bilder + (fi & farbmask)*90 + hgrunds*360 +
  580.           ((fi & figmask)-1)*60;
  581.         DrawImage( rp, &bild, (long)x, (long)y );
  582.     }
  583. }
  584.  
  585. BlinkFeld( fe, fa )
  586.     Feld fe;
  587.     Farbe fa;
  588. {
  589.     int fx, fy, x, y, i;
  590.  
  591.      /* Bildschirmposition: */
  592.     fx = fe >> 4;
  593.     fy = fe & yposmask;
  594.     if( fa == weiss ) {
  595.         x = 14+fx*40; y = 185-fy*20;
  596.     } else {
  597.         x = 374-fx*40; y = 5+fy*20;
  598.     }
  599.  
  600.     SetDrMd( rp, JAM1 | COMPLEMENT );
  601.     for( i=0; i<4; i++ ) {
  602.         RectFill( rp, (long)x+2, (long)y+1, (long)x+37, (long)y+18 );
  603.         if( i < 3 )
  604.             Delay( 15L );
  605.     }
  606.     SetDrMd( rp, JAM1 );
  607. }
  608.  
  609. NotierZug( str )
  610.     char *str;
  611. {
  612.     char num[ 5 ];
  613.  
  614.     nfarbe = (nfarbe == weiss) ? schwarz : weiss;
  615.     if( nfarbe == weiss ) {
  616.         zuege ++;
  617.         sprintf( num, "%3d.", zuege+1 );
  618.         if( zuege >= 19 ) {
  619.             ClipBlit( rp, 410L, 40L, rp, 410L, 32L, 200L, 144L, (long)0xc0 );
  620.             SetAPen( rp, 0L );
  621.             RectFill( rp, 410L, 176L, 609L, 183L );
  622.             SetAPen( rp, 1L );
  623.             Move( rp, 420L, (long)176+bline );
  624.             Text( rp, num, 4L );
  625.             Move( rp, 462L, (long)176+bline );
  626.         } else {
  627.             Move( rp, 420L, (long)32+zuege*8+bline );
  628.             Text( rp, num, 4L );
  629.             Move( rp, 462L, (long)32+zuege*8+bline );
  630.         }
  631.     if( pfh ) {
  632.         Write( pfh, "\n", 1L );
  633.         Write( pfh, num, 4L );
  634.         Write( pfh, "   ", 3L );
  635.     }
  636.     } else {
  637.         if( zuege >= 18 )
  638.             Move( rp, 536L, (long)176+bline );
  639.         else
  640.             Move( rp, 536L, (long)32+zuege*8+bline );
  641.     if( pfh )
  642.         Write( pfh, "\t       ", 8L );
  643.     }
  644.  
  645.     Text( rp, str, (long)strlen(str) );
  646.     if( pfh )
  647.     Write( pfh, str, (long)strlen(str) );
  648. }
  649.  
  650. NotierAdd( str )
  651.     char *str;
  652. {
  653.     int x, y;
  654.  
  655.     x = (nfarbe == weiss) ? 510 : 584;
  656.     y = (zuege >= 18) ? 176 : 32+zuege*8;
  657.  
  658.     Move( rp, (long)x, (long)y+bline );
  659.     Text( rp, str, (long)strlen(str) );
  660.     if( pfh )
  661.     Write( pfh, str, (long)strlen(str) );
  662. }
  663.  
  664. ZeichneStat( s, zs )
  665.     Figur s[ 9 ][ 9 ];
  666.     struct Zugstat *zs;
  667. {
  668.     char line1[ 25 ], line2[ 25 ], line3[ 25 ];
  669.  
  670.     if( zs ) { /* neue Statistik: */
  671.         sprintf( line1, "%7ld Züge in %2ld:%2ld,%2ld", zs->knoten,
  672.           zs->zeit/6000, zs->zeit/100%60, zs->zeit%100 );
  673.         if( (zs->zeit/100%60) < 10 ) line1[ 19 ] = '0';
  674.         if( (zs->zeit%100) < 10 )    line1[ 22 ] = '0';
  675.         sprintf( line2, "ca. %5d Züge/Sekunde",
  676.           (int)(zs->knoten*100/zs->zeit) );
  677.         sprintf( line3, "Wertung f. weiss: %-5d", zs->wertung );
  678.  
  679.         Move( rp, 414L, (long)208+bline );  Text( rp, line1, 24L );
  680.         Move( rp, 422L, (long)216+bline );  Text( rp, line2, 22L );
  681.         Move( rp, 418L, (long)224+bline );  Text( rp, line3, 23L );
  682.     } else { /* alte Statistik löschen: */
  683.         SetAPen( rp, 0L );
  684.         RectFill( rp, 414L, 208L, 605L, 231L );
  685.         SetAPen( rp, 1L );
  686.     }
  687. }
  688.  
  689. HLinie( xvon, yvon, xbis )
  690.     int xvon, yvon, xbis;
  691. {
  692.     Move( rp, (long)xvon, (long)yvon );
  693.     Draw( rp, (long)xbis, (long)yvon );
  694. }
  695.  
  696. VLinie( xvon, yvon, ybis )
  697.     int xvon, yvon, ybis;
  698. {
  699.      /* doppelte Strichstärke wg. HIRES */
  700.     Move( rp, (long)xvon, (long)yvon );
  701.     Draw( rp, (long)xvon, (long)ybis );
  702.     Move( rp, (long)xvon+1, (long)yvon );
  703.     Draw( rp, (long)xvon+1, (long)ybis );
  704. }
  705.  
  706. Zeit( zeit )
  707.     long *zeit;
  708. {
  709.     static long stamp1[ 3 ];
  710.     long stamp2[ 3 ];
  711.  
  712.     if( zeit ) { /* Stoppuhr stoppen, Zeit ermitteln: */
  713.         DateStamp( stamp2 );
  714.         *zeit = (stamp2[ 0 ]-stamp1[ 0 ])*8640000L +
  715.           (stamp2[ 1 ]-stamp1[ 1 ])*6000 + (stamp2[ 2 ]-stamp1[ 2 ])*2;
  716.     } else /* Stoppuhr starten: */
  717.         DateStamp( stamp1 );
  718. }
  719.  
  720. struct Knoten * GibKnoten()
  721. {
  722.     return( AllocMem( (long)sizeof( struct Knoten ), 0L ) );
  723. }
  724.  
  725. NimmKnoten( k )
  726.     struct Knoten *k;
  727. {
  728.     FreeMem( k, (long)sizeof( struct Knoten ) );
  729. }
  730.  
  731. extern int Spielstaerke;
  732.  
  733. static char dummybuf[100];
  734.  
  735. void SpielstaerkeAnzeige()
  736. {
  737.   strcpy(dummybuf,"chss V1.1a - Spielstärke: ");
  738.   if( Spielstaerke == 2 )
  739.     strcat( dummybuf,"Einfach (geht schnell)");
  740.   else if( Spielstaerke == 3 )
  741.     strcat( dummybuf,"Mittel (dauert länger)");
  742.   else
  743.     strcat( dummybuf,"Schwer (Geduld ist gefragt)");
  744.  
  745.   SetWindowTitles( win, -1, dummybuf );
  746. }
  747.  
  748. void DruckeProtokoll()
  749. {
  750.   BOOL Abort=FALSE;
  751.   char zeichen;
  752.  
  753.   if( pfh ) {
  754.     FILE *druck=fopen("prt:","w");
  755.     if( druck ) {
  756.       Seek( pfh, 0L, OFFSET_BEGINNING );
  757.       while( (Read( pfh, &zeichen, 1) > 0) && Abort==FALSE )
  758.         if( fwrite(&zeichen,1,1,druck) != 1 )
  759.           Abort=TRUE;
  760.       Seek( pfh, 0L, OFFSET_END );
  761.       fclose( druck );
  762.     }
  763.   }
  764. }
  765.